// pages/recommend/components/like/like.js
const http = require("../../../../utils/http.js")
const app = getApp()

Component({
  /**
   * 页面的初始数据
   */
  properties: {
    isHidden: {
      type: Boolean,
      value: true
    }
  },
  data: {
    cardList: [],

    pageIndex: 1,
    pageSize: 10,
    totalPage: 0
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      this.getData();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    }
  },
  methods: {
    getData: function() {
      let that = this;
      that.setData({
        pageIndex: 1,
        pageSize: 5,
        totalPage: 0
      })
      let param = {
        pageIndex: that.data.pageIndex,
        pageSize: that.data.pageSize
      }
      http.get("/poi/getLike", param)
        .then(res => {
          if (res.data.status == 200 && res.data.data.resultList != null) {
            this.setData({
              totalPage: res.data.data.totalPage,
              cardList: res.data.data.resultList
            })
          }
        })


    },
    addData() {
      let that = this;
      if (that.data.pageIndex >= that.totalPage){
        return;
      }

      that.setData({
        pageIndex: ++that.data.pageIndex,
        pageSize: 5
      })
      let param = {
        pageIndex: that.data.pageIndex,
        pageSize: that.data.pageSize
      }
      http.get("/poi/getLike", param)
        .then(res => {
          if (res.data.status == 200 && res.data.data.resultList != null) {
            this.setData({
              totalPage: res.data.data.totalPage,
              cardList: this.data.cardList.concat(res.data.data.resultList)
            })
          }
        })
    },
    toPoiDetail: function(e) {
      let poiId = e.currentTarget.dataset.poiid
      wx.navigateTo({
        url: '/pages/location/poidetail/poidetail?poiId=' + poiId,
      })
    },
    toMddDetail: function(e) {
      let mddId = e.currentTarget.dataset.mddid
      wx.navigateTo({
        url: '/pages/destination/views/detail/detail?mddId=' + mddId,
      })
    }
  }
})